package cn.sl;

import cn.sl.exce.ExcelListener;
import cn.sl.pojo.ExcelFields;
import com.alibaba.excel.EasyExcel;
import javax.swing.filechooser.FileSystemView;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Irving
 * @create 2021/6/19
 * @desc
 **/
public class Main {

    /**
     * Excel存储和写入的路径
     */
    public static final File file=new File(FileSystemView.getFileSystemView().getHomeDirectory().getPath()+File.separator+"Test.xlsx");

    public static void main(String[] args) {
        read();
    }

    /**
     * 写入数据
     */
    public static void write(){
        //要插入的数据
        List<ExcelFields> excelFieldsList=new ArrayList<ExcelFields>();
        for (int i = 0; i < 10; i++) {
            ExcelFields excelFields=new ExcelFields("Irving"+i,"18","110");
            excelFieldsList.add(excelFields);
        }
        //插入数据
        EasyExcel.write(file,ExcelFields.class).sheet("个人信息").doWrite(excelFieldsList);
    }

    public static void read(){
        EasyExcel.read(file,ExcelFields.class,new ExcelListener()).sheet("个人信息").doRead();
    }

}
